/*
	Copyright 2006, 2007, 2008, 2009, 2010 Bastiaan Grutters
    
    This file is part of Ages of Strife updater.

    Ages of Strife updater is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Ages of Strife updater is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Ages of Strife updater.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.awt.Button;
import java.awt.Container;
import java.awt.Label;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Overview extends Container implements ActionListener {

	private static final long serialVersionUID = 3258134673766101044L;
	private Label turn, userCount, rulerCount, status;
	private Button start, stop, generate;
	private AgesOfStrifeServer parent;
	
	public Overview( AgesOfStrifeServer parent ) {
		this.parent = parent;
		
		turn = new Label( "Turn: " );
		turn.setBounds( 10, 50, 120, 22 );
		add( turn );

		status = new Label( "Status: " );
		status.setBounds( 10, 80, 240, 22 );
		add( status );

		userCount = new Label( "Total users: " );
		userCount.setBounds( 10, 110, 120, 22 );
		add( userCount );
		
		rulerCount = new Label( "Total rulers: " );
		rulerCount.setBounds( 10, 140, 120, 22 );
		add( rulerCount );
		
		start = new Button( "Start" );
		start.setBounds( 10, 170, 80, 22 );
		start.addActionListener( this );
		start.setEnabled( false );
		add( start );
		
		stop = new Button( "Stop" );
		stop.setBounds( 100, 170, 80, 22 );
		stop.addActionListener( this );
		stop.setEnabled( false );
		add( stop );
		
		generate = new Button( "Reset game" );
		generate.setBounds( 190, 170, 80, 22 );
		generate.addActionListener( this );
		generate.setEnabled( false );
		add( generate );
	}

	public void actionPerformed( ActionEvent ae ) {
		if( ae.getSource().equals( start ) ) {
			start.setEnabled( false );
			stop.setEnabled( true );
			parent.start();
		}
		else if( ae.getSource().equals( stop ) ) {
			start.setEnabled( true );
			stop.setEnabled( false );
			//parent.stop();
		}
		else if( ae.getSource().equals( generate ) ) {
			status.setText( "Status: Resetting database..." );
			parent.resetGame();
			status.setText( "Status: New game ready!" );
		}
	}
	
	public void setTurn( int turn ) {
		this.turn.setText( "Turn: " + turn );
	}
	
	public void setSpeed( int speed ) {
		
	}

	public void setMaxTurn( int maxTurn ) {
		
	}

	public void setCountDown( int countDown ) {
		int minutes = countDown / 60;
		int seconds = countDown % 60;
		String secs = "" + seconds;
		if( secs.length() < 2 ) secs = "0" + secs; 
		status.setText( "Status: next turn in " + minutes + ":" + secs );
	}

	
	public void setRulerCount( int rulerCount ) {
		AgesOfStrifeServer.log.info( "Game information retrieved." );
		if( parent.getResetGameEnabled() ) {
			generate.setEnabled( true );
		}
		start.setEnabled( true ); 
		this.rulerCount.setText( "Total rulers: " + rulerCount );
	}
	
	public void setUserCount( int userCount ) {
		this.userCount.setText( "Total users: " + userCount );
	}
	
	public void setStatus( String status ) {
		this.status.setText( "Status: " + status );
	}
}
